package zhongbo.java.websocket.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import zhongbo.java.websocket.demo.web.websocket.ChatHandler;

/**
 * WebSocket方式 1 添加Handler方式
 */
// WebSocketConfig.java
@Configuration
@EnableWebSocket
public class WebSocketHandlerConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new ChatHandler(), "/chat0")
                .setAllowedOrigins("*"); // 允许所有域名访问  
    }
}  